home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / dc14 / src / main.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  3KB  |  141 lines

  1. /****************************************************
  2.  
  3.             Document Chain   version 1.4
  4.                                 ALGO [TOOLS no.02]
  5.                                 
  6.                                 1994.02.14
  7.                                         
  8. ******************************************************/
  9. #include<stdio.h>
  10. #include<string.h>
  11. #include<dos.h>
  12. #include<direct.h>
  13. #include<ctype.h>
  14. #include<stdlib.h>
  15. #include"list.h"
  16. #include"chain.h"
  17.  
  18. #define        TRUE    (-1)
  19. #define        FALSE    0
  20. #define        VERSION        "ver 1.4"
  21. #define     DATE        "1994.02.08"
  22.  
  23. LIST        head;
  24. PARA        infile,outfile;
  25. int            size=65535;        /* ファイルのトータルサイズ     */
  26. int            cnt=0;            /* ファイルカウンター            */
  27. FILE        *ofp;            /* 出力用のファイルポインター    */
  28. char        file[14];        /* ファイルネーム用バッファ     */
  29.  
  30.  
  31. void CmdAnalyse(char *st,PARA *pa); /* 作ったあとで _splitpathを使えば
  32.                                         いいことを知った... */
  33. void msg(void);
  34. void usage(void);
  35.  
  36. void main(int argc,char *argv[])
  37. {
  38.     int i,n,dmy;
  39.     char in_flag=FALSE,*p=NULL;
  40.     
  41.     if(argc==1){
  42.         usage();exit(0);
  43.     }
  44.     
  45.     for(i=1;i<argc;i++){
  46.         if((*p=*argv[i])=='-'){
  47.             *p=*(++argv[i]);
  48.             switch(toupper(*p)){
  49.             case    'D':    /* 只今整備中(^^;) */
  50.                             break;
  51.             case    'S':    size=atoi(++argv[i])*1024;
  52.                             if(size<512 || size>1024*1024){
  53.                                 fprintf(stderr,"サイズの指定に誤りがあります\n");
  54.                                 exit(1);
  55.                             }
  56.                             break;
  57.             }
  58.         }else{
  59.             if(in_flag==FALSE){
  60.                 CmdAnalyse(argv[i],&infile);
  61.                 in_flag=TRUE;
  62.             }else{
  63.                 CmdAnalyse(argv[i],&outfile);
  64.             }
  65.         }
  66.     }
  67.     
  68.     msg();
  69.     printf("File size  %05d byte.\n",size);
  70.     printf("Make target file list");
  71.     n=MakeList(infile);
  72.     printf("(%03d targets).\n",n);
  73.     printf("Line count.\n");
  74.     for(i=0;i<n;i++)printf(".");
  75.     printf("\r");
  76.     LineCount();
  77.     printf("\n");
  78.     
  79.     _dos_setdrive(outfile.drive,(unsigned int *)&dmy);
  80.     if(outfile.path[0] != '\0')
  81.         if (_chdir(outfile.path)==ERR){
  82.             printf("ディレクトリの指定が違います.");
  83.             exit(1);
  84.         }
  85.     while((cnt=SetFlag(size))!=0){
  86.         WriteOpenName(file);
  87.         if((ofp=fopen(file,"w"))==NULL){
  88.             fprintf(stderr,"Fine open error.'%s'",file);
  89.             exit(1);
  90.         }
  91.         printf("Create '%s' \n",file);
  92.         MakeIndex(cnt);
  93.         Chain(cnt);
  94.         fclose(ofp);
  95.         ClearFlag();
  96.     }
  97.     ClearFlag();
  98.     return;
  99. }
  100.  
  101.  
  102. void CmdAnalyse(char *st,PARA *pa)
  103. {
  104.     char *p;
  105.     unsigned int drv;
  106.     
  107.     
  108.     if((p=strchr(st,':'))!=NULL) {
  109.         pa->drive=toupper(*(p-1))-'A'+1;
  110.         st=p+1;
  111.     }else{
  112.         _dos_getdrive(&drv);
  113.         pa->drive=drv;
  114.     }
  115.     
  116.     if((p=strrchr(st,'\\'))!=NULL){
  117.         if(p==st){
  118.             strcpy(pa->path,"\\\0");
  119.             st++;
  120.         }else{
  121.             *p='\0';
  122.             strcpy(pa->path,st);
  123.             st=p+1;
  124.         }
  125.     }
  126.     strcpy(pa->file,st);
  127. }
  128.  
  129. void msg(void)
  130. {
  131.     printf("<<Document Chain %s>>  [TOOLS NO.02] ALGO\n",VERSION);
  132. }
  133.  
  134. void usage(void)
  135. {
  136.     msg();
  137.     printf("   usage: run386 dc <option> <target file> <output file>\n");
  138.     printf("   option ... -sxx  一つの分割ファイルのファイルの大きさ\n");
  139.     printf("                    単位はkb。省略時は64kb固定。\n");
  140. }
  141.